package com.googlecode.cswish;

import java.io.StringWriter;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.views.jsp.AbstractUITagTest;
import org.apache.struts2.views.jsp.StrutsMockHttpServletRequest;
import org.apache.struts2.views.jsp.StrutsMockPageContext;
import org.apache.struts2.views.jsp.StrutsMockServletContext;
import org.junit.After;
import org.junit.Before;

import com.googlecode.cswish.struts.spring.ObjectFactory;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.util.ValueStack;

public class BaseStrutsUITestCase extends BaseSpringTestCase {
	protected Action action;
    protected Map context;
    protected Map session;
    protected ValueStack stack;
    
	protected StringWriter writer;
    protected StrutsMockHttpServletRequest request;
    protected StrutsMockPageContext pageContext;
    protected HttpServletResponse response;
    protected StrutsMockServletContext servletContext;
    
    protected Container container;
    
	protected UITagTestCase uiTagTest = new UITagTestCase(this);
	
	class UITagTestCase extends AbstractUITagTest {
		BaseStrutsUITestCase testCase;
		
		UITagTestCase(BaseStrutsUITestCase testCase) {
			this.testCase = testCase;
		}
		
		public void setUp() throws Exception {
			super.setUp();
			
			testCase.action = this.action;
			testCase.context = this.context;
			testCase.session = this.session;
			testCase.stack = this.stack;
			
			testCase.writer = this.writer;
			testCase.request = this.request;
			testCase.pageContext = this.pageContext;
			testCase.response = this.response;
			testCase.servletContext = this.servletContext;
			
			testCase.container = this.container;
		}
		
		public void tearDown() throws Exception {
			super.tearDown();
		}
		
		public Container getContainer() {
			return super.container;
		}
	};
	
	@Before
	public void setUp() throws Exception {
		uiTagTest.setUp();
		
		objectFactory = (ObjectFactory) container.getInstance(
        		com.opensymphony.xwork2.ObjectFactory.class);
		super.setUp();
	}
	
	@After
	public void tearDown() throws Exception {
//		uiTagTest.tearDown();
//		
//		super.tearDown();
	}
}